﻿using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace ASPItalia.ModelVirtualCasting.Web.Utils
{
    public static class UrlExtensions
    {
        private static string baseImageUrlFormatString;

        static UrlExtensions()
        {
            baseImageUrlFormatString = Configuration.BaseImageUrl;
        }

		public static string ToImageAbsoluteUrl(this string relativeUrl)
		{
			return VirtualPathUtility
				.ToAbsolute(string.Format(string.Format(baseImageUrlFormatString, relativeUrl)));
		}


        public static string ToThumbnailAbsoluteUrl(this string relativeUrl)
        {
			return ToImageAbsoluteUrl("thumbs/" + relativeUrl);
        }

		public static string ToVideoAbsoluteUrl(this string relativeUrl)
		{
			return VirtualPathUtility
				.ToAbsolute(string.Format(string.Format(baseImageUrlFormatString, "videos/" + relativeUrl)));
		}


        public static string ToAbsoluteUrl(this string relativeUrl)
        {
            return VirtualPathUtility
                .ToAbsolute(string.Format(string.Format(baseImageUrlFormatString, relativeUrl)));
        }

        public static string GetUrl(this HtmlHelper html, string routeName, string controller, string action, object routeValues)
        {
            return UrlHelper.GenerateUrl(
                routeName,
                action, controller, new RouteValueDictionary(routeValues),
                RouteTable.Routes, html.ViewContext.RequestContext, false);
        }

        public static bool IsIpad(this HttpBrowserCapabilitiesBase capabilities)
        {
            object o = capabilities["IsIPad"];
            bool result = o == null ? false : o.ToString() == true.ToString();

            return result;
        }
    }
}